package com.sunye.rabbit_mq_2;


import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/rabbitMqController")
public class RabbitBeanController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 广播模式
     * @return
     */
    @RequestMapping("/rabbitBeanFanoutMessage")
    public String rabbitBeanFanoutMessage(){
        rabbitTemplate.convertAndSend("fanoutExchange","","这是生产的消息");
        return "sucess";
    }

    /**
     *  路由模式
     * @return
     */
    @RequestMapping("/rabbitBeanDirectMessage")
    public String rabbitBeanDirectMessage(){
        rabbitTemplate.convertAndSend("directExchange","orange","这是生产橙色的消息");
        rabbitTemplate.convertAndSend("directExchange","blue","这是生产蓝色的消息");
        rabbitTemplate.convertAndSend("directExchange","red","这是生产蓝色的消息");
        return "sucess";
    }

    //动态路由模式
    @RequestMapping("/rabbitBeanTopicMessage")
    public String rabbitBeanTopicMessage(){
        rabbitTemplate.convertAndSend("topicExchange","queue.red.message","被一个队列接收");
        rabbitTemplate.convertAndSend("topicExchange","number.queue.green","被2个队列接收");
        return "success";
    }






}
